﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NWN.GDY.Service.Common;
using NWN.GDY.Service.DataAccess;
using System.Text.RegularExpressions;
using Sdo.Payment.Common;
using NWN.GDY.Service.Entity;

namespace NWN.GDY.Service.Core
{
    public class UserBC
    {
        public int RegisterUser(string uid, string psd)
        {
            if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(psd))
                return GDYConsts.ReturnDefine.EmptyUIDORPSD;
            if (uid.Length < 2 || psd.Length<6)
                return GDYConsts.ReturnDefine.TOOSHORTUIDORPSD;
            string s_reg = @"^[\u4E00-\u9FA5A-Za-z0-9]+$";
            Regex reg = new Regex(s_reg);
            if (!reg.IsMatch(uid) || !reg.IsMatch(psd))
                return GDYConsts.ReturnDefine.INVALIDUIDORPSD;
            if (uid.Length > 20 || uid.Length > 20)
                return GDYConsts.ReturnDefine.TOOLONGUIDORPSD;
            return new UserDA().RegisterUser(uid, psd); 
        }

        public int UserLogin(string uid, string psd)
        {
            if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(psd))
                return GDYConsts.ReturnDefine.EmptyUIDORPSD;
            string s_reg = @"^[\u4E00-\u9FA5A-Za-z0-9]+$";
            Regex reg = new Regex(s_reg);
            if (!reg.IsMatch(uid) || !reg.IsMatch(psd))
                return GDYConsts.ReturnDefine.INVALIDUIDORPSD;
            return new UserDA().UserLogin(uid, psd);
        }

        public User GetUser(string uid)
        {
            try
            {
                return new UserDA().GetUser(uid);
            }
            catch (Exception x)
            {
                Log.Error(x);
                return null;
            }
        }

    }
}
